
'use strict';
let inquirer = require('inquirer'),
    cp = require('child_process'),
    fs = require('fs');
function  set() {
    let questions = [
        {
            type: 'input',
            name: 'project_name',
            message: 'What\'s your project name'
        },
        {
            type: 'input',
            name: 'install_path',
            message: 'What\'s your project install_path',
            default: function () {
                return __dirname;
            }
        },
        {
            type: 'confirm',
            name: 'isStrict',
            message: 'open strict mode',
            default: function () {
                return true;
            }
        },
        {
            type: 'confirm',
            name: 'isInstall',
            message: 'install the project now',
            default: function () {
                return true;
            }
        }
    ];

    inquirer.prompt(questions).then(function (answers) {
        fs.writeFile('./lib/init.json', JSON.stringify(answers, null, '  '), (err)){
            if (err) throw err;
    })
        ;
        install();

    });
    function install() {
        fs.readFile('./lib/init.json', function (err, data) {
            if (err) throw err;
            let jsonObj = JSON.parse(data),
                project_name = jsonObj['project_name'],
                install_path = jsonObj['install_path'],
                isStrict = jsonObj['isStrict'],
                isInstall = jsonObj['isInstall'];
            if (isInstall) {
                console.log("running…");
                cp.exec('npm uninstall gulp -d', function (err) {

                    if (err)  throw err;
                    console.log("done!");
                })
            }
            else {
                console.log("uninstall");
            }
        })
    }
}
module.exports=set;